package cn.edu.zut.internship.web.controller.sys;

import cn.edu.zut.internship.bean.sys.Result;
import cn.edu.zut.internship.bean.sys.SysUser;
import cn.edu.zut.internship.entity.AuthSysUser;
import cn.edu.zut.internship.iservice.student.StudentSV;
import cn.edu.zut.internship.iservice.sys.IUserService;
import cn.edu.zut.internship.iservice.teach.TeachSV;
import cn.edu.zut.internship.web.utils.UserInfoUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/user")
public class UserController {
    @Reference
    private IUserService userService;
    @Reference
    private TeachSV teachSV;
    @Reference
    private StudentSV studentSV;
    @PostMapping("/search")
    public Result searchUsers(@RequestBody Map params){
        Result result = new Result();
        result = userService.findAll(params);
        return result;
    }

    /**
     * 更新用户角色信息
     * @param user
     * @return
     */
    @RequestMapping("/update/roles")
    public Result assignUserRoles(@RequestBody Map user){
        Result result = new Result();
        this.userService.assignUserRoles(user);
        return result;
    }

    /**
     * 导入教师信息
     * @param params
     * @return
     */
    @RequestMapping("/importTeach")
    public Result importTeach(@RequestBody Map params){
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        String userAccount = userInfo.getUserAccount();
        params.put("creatAccount",userAccount);
        result = teachSV.importTeach(params);
        return result;
    }

    /**
     * 导入学生信息
     * @param params
     * @return
     */
    @RequestMapping("/importStudent")
    public Result importStudent(@RequestBody Map params){
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        String userAccount = userInfo.getUserAccount();
        params.put("creatAccount",userAccount);
        result = studentSV.importStudent(params);
        return result;
    }
    @RequestMapping("/addUser")
    public Result addUser(@RequestBody Map params){
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        String userAccount = userInfo.getUserAccount();
        params.put("creatAccount",userAccount);
        result = userService.addUser(params);
        return result;
    }
    @RequestMapping("/deleteUser")
    public Result deleteUser(@RequestBody Map params){
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        String userAccount = userInfo.getUserAccount();
        params.put("creatAccount",userAccount);
        result = userService.deleteUser(params);
        return result;
    }

    /**
     * 列表查询未分配导师的学生
     * @param params
     * @return
     */
    @RequestMapping("/getStudentList")
    public Result getStudentList(@RequestBody Map params){
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        String userAccount = userInfo.getUserAccount();
        params.put("creatAccount",userAccount);
        result = studentSV.getNoTeachStudent(params);
        return result;
    }

    /**
     * 更新用户信息接口
     * @param params
     * @return
     */
    @RequestMapping("/updateUser")
    public Result updateUser(@RequestBody Map params){
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        String userAccount = userInfo.getUserAccount();
        params.put("updateAccount",userAccount);
        result = userService.updateUser(params);
        return result;
    }

    /**
     * 获取用户公开信息
     * @param params
     * @return
     */
    @RequestMapping("/getUser")
    public Result getUser(@RequestBody Map params){
        Result result = new Result();
        result = userService.getUser(params);
        return result;
    }

    /**
     * 获取学生用户的报告填写信息
     * @param params
     * @return
     */
    @RequestMapping("/getUserReportInfo")
    public Result getUserReportInfo(@RequestBody Map params){
        Result result = new Result();
        result = userService.getUserReportInfo(params);
        return result;
    }
}
